package com.example.zhangxin.comevedio.activity.fragment;


import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

import com.example.zhangxin.comevedio.R;
import com.example.zhangxin.comevedio.activity.adapter.PopularAdapter;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshListView;

import java.util.Timer;
import java.util.TimerTask;


public class PopularFragment extends BaseFragment {


    private PullToRefreshListView refresh_list;

    @Override
    protected void setData() {
        refresh_list.setAdapter(new PopularAdapter());
        ListView listView = refresh_list.getRefreshableView();
        listView.addHeaderView(View.inflate(getActivity(), R.layout.popular_head, null));
        refresh_list.onRefreshComplete();
        refresh_list.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) {
                Timer timer = new Timer();
                timer.schedule(new TimerTask() {
                    @Override
                    public void run() {
                        getActivity().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(getActivity(),"onPullDownToRefresh",Toast.LENGTH_SHORT).show();
                                refresh_list.onRefreshComplete();
                            }
                        });
                    }
                },2000);

            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) {
                Toast.makeText(getActivity(),"onPullUpToRefresh",Toast.LENGTH_SHORT).show();
            }
        });
    }

    @Override
    protected void findView(View view) {
        refresh_list = (PullToRefreshListView) view.findViewById(R.id.refresh_list);


    }

    @Override
    public View getLayout() {
        return View.inflate(getActivity(), R.layout.fragment_popular, null);
    }

}
